home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 March / PCWMAR09.iso / Software / Freeware / Adobe Media Player 1.6 / adobe_media_player.air / AMP.swf / scripts / mx / controls / FlexNativeMenu.as < prev    next >
Encoding:
Text File  |  2008-11-25  |  25.7 KB  |  850 lines

  1. package mx.controls
  2. {
  3.    import flash.display.InteractiveObject;
  4.    import flash.display.NativeMenu;
  5.    import flash.display.NativeMenuItem;
  6.    import flash.display.Stage;
  7.    import flash.events.Event;
  8.    import flash.events.EventDispatcher;
  9.    import flash.events.TimerEvent;
  10.    import flash.ui.Keyboard;
  11.    import flash.utils.Timer;
  12.    import flash.xml.XMLNode;
  13.    import mx.collections.ArrayCollection;
  14.    import mx.collections.ICollectionView;
  15.    import mx.collections.XMLListCollection;
  16.    import mx.collections.errors.ItemPendingError;
  17.    import mx.controls.menuClasses.IMenuDataDescriptor;
  18.    import mx.controls.treeClasses.DefaultDataDescriptor;
  19.    import mx.core.Application;
  20.    import mx.core.EventPriority;
  21.    import mx.core.UIComponentGlobals;
  22.    import mx.core.mx_internal;
  23.    import mx.events.CollectionEvent;
  24.    import mx.events.CollectionEventKind;
  25.    import mx.events.FlexNativeMenuEvent;
  26.    import mx.managers.ILayoutManagerClient;
  27.    import mx.managers.ISystemManager;
  28.    
  29.    use namespace mx_internal;
  30.    
  31.    public class FlexNativeMenu extends EventDispatcher implements ILayoutManagerClient, IFlexContextMenu
  32.    {
  33.       mx_internal static const VERSION:String = "3.2.0.3958";
  34.       
  35.       private static var MNEMONIC_INDEX_CHARACTER:String = "_";
  36.       
  37.       private var _labelField:String = "label";
  38.       
  39.       private var _initialized:Boolean = false;
  40.       
  41.       private var _keyEquivalentFunction:Function;
  42.       
  43.       private var keyEquivalentFieldChanged:Boolean = false;
  44.       
  45.       private var _mnemonicIndexFunction:Function;
  46.       
  47.       private var showRootChanged:Boolean = false;
  48.       
  49.       private var _mnemonicIndexField:String = "mnemonicIndex";
  50.       
  51.       private var invalidatePropertiesFlag:Boolean = false;
  52.       
  53.       private var _hasRoot:Boolean = false;
  54.       
  55.       private var labelFieldChanged:Boolean = false;
  56.       
  57.       private var _keyEquivalentModifiersFunction:Function;
  58.       
  59.       private var dataProviderChanged:Boolean = false;
  60.       
  61.       private var _nestLevel:int = 1;
  62.       
  63.       private var _processedDescriptors:Boolean = false;
  64.       
  65.       private var _updateCompletePendingFlag:Boolean = false;
  66.       
  67.       private var mnemonicIndexFieldChanged:Boolean = false;
  68.       
  69.       private var _nativeMenu:NativeMenu;
  70.       
  71.       private var dataDescriptorChanged:Boolean = false;
  72.       
  73.       private var _dataDescriptor:IMenuDataDescriptor;
  74.       
  75.       private var _showRoot:Boolean = true;
  76.       
  77.       mx_internal var _rootModel:ICollectionView;
  78.       
  79.       private var _labelFunction:Function;
  80.       
  81.       private var keyEquivalentModifiersFunctionChanged:Boolean = false;
  82.       
  83.       private var _keyEquivalentField:String = "keyEquivalent";
  84.       
  85.       public function FlexNativeMenu()
  86.       {
  87.          _nativeMenu = new NativeMenu();
  88.          _dataDescriptor = new DefaultDataDescriptor();
  89.          _keyEquivalentModifiersFunction = keyEquivalentModifiersDefaultFunction;
  90.          super();
  91.          _nativeMenu.addEventListener(Event.DISPLAYING,menuDisplayHandler,false,0,true);
  92.       }
  93.       
  94.       public function get nestLevel() : int
  95.       {
  96.          return _nestLevel;
  97.       }
  98.       
  99.       [Bindable("nativeMenuUpdate")]
  100.       public function get nativeMenu() : NativeMenu
  101.       {
  102.          return _nativeMenu;
  103.       }
  104.       
  105.       public function set nestLevel(param1:int) : void
  106.       {
  107.          _nestLevel = param1;
  108.          invalidateProperties();
  109.       }
  110.       
  111.       public function get updateCompletePendingFlag() : Boolean
  112.       {
  113.          return _updateCompletePendingFlag;
  114.       }
  115.       
  116.       [Bindable("mnemonicIndexFunctionChanged")]
  117.       public function get mnemonicIndexFunction() : Function
  118.       {
  119.          return _mnemonicIndexFunction;
  120.       }
  121.       
  122.       [Bindable("keyEquivalentFunctionChanged")]
  123.       public function get keyEquivalentFunction() : Function
  124.       {
  125.          return _keyEquivalentFunction;
  126.       }
  127.       
  128.       protected function parseLabelToMnemonicIndex(param1:String) : int
  129.       {
  130.          var _loc7_:String = null;
  131.          var _loc8_:int = 0;
  132.          var _loc2_:RegExp = new RegExp(MNEMONIC_INDEX_CHARACTER + MNEMONIC_INDEX_CHARACTER,"g");
  133.          var _loc3_:Array = param1.split(_loc2_);
  134.          var _loc4_:int = int(_loc3_.length);
  135.          var _loc5_:int = 0;
  136.          var _loc6_:int = 0;
  137.          while(_loc6_ < _loc4_)
  138.          {
  139.             _loc7_ = String(_loc3_[_loc6_]);
  140.             _loc8_ = int(_loc7_.indexOf(MNEMONIC_INDEX_CHARACTER));
  141.             if(_loc8_ >= 0)
  142.             {
  143.                return _loc8_ + _loc5_;
  144.             }
  145.             _loc5_ += _loc7_.length + MNEMONIC_INDEX_CHARACTER.length;
  146.             _loc6_++;
  147.          }
  148.          return -1;
  149.       }
  150.       
  151.       public function validateSize(param1:Boolean = false) : void
  152.       {
  153.       }
  154.       
  155.       public function set updateCompletePendingFlag(param1:Boolean) : void
  156.       {
  157.          _updateCompletePendingFlag = param1;
  158.       }
  159.       
  160.       private function clearMenu(param1:NativeMenu) : void
  161.       {
  162.          var _loc2_:int = int(param1.numItems);
  163.          var _loc3_:int = 0;
  164.          while(_loc3_ < _loc2_)
  165.          {
  166.             param1.removeItemAt(0);
  167.             _loc3_++;
  168.          }
  169.       }
  170.       
  171.       public function set mnemonicIndexFunction(param1:Function) : void
  172.       {
  173.          if(_mnemonicIndexFunction != param1)
  174.          {
  175.             _mnemonicIndexFunction = param1;
  176.             mnemonicIndexFieldChanged = true;
  177.             invalidateProperties();
  178.             dispatchEvent(new Event("mnemonicIndexFunctionChanged"));
  179.          }
  180.       }
  181.       
  182.       [Bindable("keyEquivalentChanged")]
  183.       public function get keyEquivalentField() : String
  184.       {
  185.          return _keyEquivalentField;
  186.       }
  187.       
  188.       public function set mnemonicIndexField(param1:String) : void
  189.       {
  190.          if(_mnemonicIndexField != param1)
  191.          {
  192.             _mnemonicIndexField = param1;
  193.             mnemonicIndexFieldChanged = true;
  194.             invalidateProperties();
  195.             dispatchEvent(new Event("mnemonicIndexFieldChanged"));
  196.          }
  197.       }
  198.       
  199.       private function itemSelectHandler(param1:Event) : void
  200.       {
  201.          var _loc5_:* = false;
  202.          var _loc2_:NativeMenuItem = param1.target as NativeMenuItem;
  203.          var _loc3_:String = dataDescriptor.getType(_loc2_.data).toLowerCase();
  204.          if(_loc3_ == "check")
  205.          {
  206.             _loc5_ = !dataDescriptor.isToggled(_loc2_.data);
  207.             _loc2_.checked = _loc5_;
  208.             dataDescriptor.setToggled(_loc2_.data,_loc5_);
  209.          }
  210.          var _loc4_:FlexNativeMenuEvent = new FlexNativeMenuEvent(FlexNativeMenuEvent.ITEM_CLICK);
  211.          _loc4_.nativeMenu = _loc2_.menu;
  212.          _loc4_.index = _loc2_.menu.getItemIndex(_loc2_);
  213.          _loc4_.nativeMenuItem = _loc2_;
  214.          _loc4_.label = _loc2_.label;
  215.          _loc4_.item = _loc2_.data;
  216.          dispatchEvent(_loc4_);
  217.       }
  218.       
  219.       [Bindable("keyEquivalentModifiersFunctionChanged")]
  220.       public function get keyEquivalentModifiersFunction() : Function
  221.       {
  222.          return _keyEquivalentModifiersFunction;
  223.       }
  224.       
  225.       public function set keyEquivalentFunction(param1:Function) : void
  226.       {
  227.          if(_keyEquivalentFunction != param1)
  228.          {
  229.             _keyEquivalentFunction = param1;
  230.             keyEquivalentFieldChanged = true;
  231.             invalidateProperties();
  232.             dispatchEvent(new Event("keyEquivalentFunctionChanged"));
  233.          }
  234.       }
  235.       
  236.       private function keyEquivalentModifiersDefaultFunction(param1:Object) : Array
  237.       {
  238.          var i:int = 0;
  239.          var modifier:* = undefined;
  240.          var data:Object = param1;
  241.          var modifiers:Array = [];
  242.          var xmlModifiers:Array = ["@altKey","@cmdKey","@ctrlKey","@shiftKey"];
  243.          var objectModifiers:Array = ["altKey","cmdKey","ctrlKey","shiftKey"];
  244.          var keyboardModifiers:Array = [Keyboard.ALTERNATE,Keyboard.COMMAND,Keyboard.CONTROL,Keyboard.SHIFT];
  245.          if(data is XML)
  246.          {
  247.             i = 0;
  248.             while(i < xmlModifiers.length)
  249.             {
  250.                try
  251.                {
  252.                   modifier = data[xmlModifiers[i]];
  253.                   if(modifier[0] == true)
  254.                   {
  255.                      modifiers.push(keyboardModifiers[i]);
  256.                   }
  257.                }
  258.                catch(e:Error)
  259.                {
  260.                }
  261.                i++;
  262.             }
  263.          }
  264.          else if(data is Object)
  265.          {
  266.             i = 0;
  267.             while(i < objectModifiers.length)
  268.             {
  269.                try
  270.                {
  271.                   modifier = data[objectModifiers[i]];
  272.                   if(String(modifier).toLowerCase() == "true")
  273.                   {
  274.                      modifiers.push(keyboardModifiers[i]);
  275.                   }
  276.                }
  277.                catch(e:Error)
  278.                {
  279.                }
  280.                i++;
  281.             }
  282.          }
  283.          return modifiers;
  284.       }
  285.       
  286.       private function menuDisplayHandler(param1:Event) : void
  287.       {
  288.          var _loc2_:NativeMenu = param1.target as NativeMenu;
  289.          var _loc3_:FlexNativeMenuEvent = new FlexNativeMenuEvent(FlexNativeMenuEvent.MENU_SHOW);
  290.          _loc3_.nativeMenu = _loc2_;
  291.          dispatchEvent(_loc3_);
  292.       }
  293.       
  294.       private function populateMenu(param1:NativeMenu, param2:ICollectionView) : NativeMenu
  295.       {
  296.          var menu:NativeMenu = param1;
  297.          var collection:ICollectionView = param2;
  298.          var collectionLength:int = collection.length;
  299.          var i:int = 0;
  300.          while(i < collectionLength)
  301.          {
  302.             try
  303.             {
  304.                insertMenuItem(menu,i,collection[i]);
  305.             }
  306.             catch(e:ItemPendingError)
  307.             {
  308.             }
  309.             i++;
  310.          }
  311.          return menu;
  312.       }
  313.       
  314.       public function set processedDescriptors(param1:Boolean) : void
  315.       {
  316.          _processedDescriptors = param1;
  317.       }
  318.       
  319.       [Bindable("labelFieldChanged")]
  320.       public function get labelField() : String
  321.       {
  322.          return _labelField;
  323.       }
  324.       
  325.       public function set dataDescriptor(param1:IMenuDataDescriptor) : void
  326.       {
  327.          _dataDescriptor = param1;
  328.          dataDescriptorChanged = true;
  329.       }
  330.       
  331.       private function createMenu() : NativeMenu
  332.       {
  333.          var _loc1_:NativeMenu = new NativeMenu();
  334.          _loc1_.addEventListener(Event.DISPLAYING,menuDisplayHandler,false,0,true);
  335.          return _loc1_;
  336.       }
  337.       
  338.       private function collectionChangeHandler(param1:CollectionEvent) : void
  339.       {
  340.          if(param1.kind == CollectionEventKind.ADD)
  341.          {
  342.             dataProviderChanged = true;
  343.             invalidateProperties();
  344.          }
  345.          else if(param1.kind == CollectionEventKind.REMOVE)
  346.          {
  347.             dataProviderChanged = true;
  348.             invalidateProperties();
  349.          }
  350.          else if(param1.kind == CollectionEventKind.REFRESH)
  351.          {
  352.             dataProviderChanged = true;
  353.             dataProvider = dataProvider;
  354.             invalidateProperties();
  355.          }
  356.          else if(param1.kind == CollectionEventKind.RESET)
  357.          {
  358.             dataProviderChanged = true;
  359.             invalidateProperties();
  360.          }
  361.          else if(param1.kind == CollectionEventKind.UPDATE)
  362.          {
  363.             dataProviderChanged = true;
  364.             invalidateProperties();
  365.          }
  366.       }
  367.       
  368.       public function set dataProvider(param1:Object) : void
  369.       {
  370.          var _loc3_:XMLList = null;
  371.          var _loc4_:Array = null;
  372.          if(mx_internal::_rootModel)
  373.          {
  374.             mx_internal::_rootModel.removeEventListener(CollectionEvent.COLLECTION_CHANGE,collectionChangeHandler);
  375.          }
  376.          if(typeof param1 == "string")
  377.          {
  378.             param1 = new XML(param1);
  379.          }
  380.          else if(param1 is XMLNode)
  381.          {
  382.             param1 = new XML(XMLNode(param1).toString());
  383.          }
  384.          else if(param1 is XMLList)
  385.          {
  386.             param1 = new XMLListCollection(param1 as XMLList);
  387.          }
  388.          if(param1 is XML)
  389.          {
  390.             _hasRoot = true;
  391.             _loc3_ = new XMLList();
  392.             _loc3_ += param1;
  393.             mx_internal::_rootModel = new XMLListCollection(_loc3_);
  394.          }
  395.          else if(param1 is ICollectionView)
  396.          {
  397.             mx_internal::_rootModel = ICollectionView(param1);
  398.             if(mx_internal::_rootModel.length == 1)
  399.             {
  400.                _hasRoot = true;
  401.             }
  402.          }
  403.          else if(param1 is Array)
  404.          {
  405.             mx_internal::_rootModel = new ArrayCollection(param1 as Array);
  406.          }
  407.          else if(param1 is Object)
  408.          {
  409.             _hasRoot = true;
  410.             _loc4_ = [];
  411.             _loc4_.push(param1);
  412.             mx_internal::_rootModel = new ArrayCollection(_loc4_);
  413.          }
  414.          else
  415.          {
  416.             mx_internal::_rootModel = new ArrayCollection();
  417.          }
  418.          mx_internal::_rootModel.addEventListener(CollectionEvent.COLLECTION_CHANGE,collectionChangeHandler,false,0,true);
  419.          dataProviderChanged = true;
  420.          invalidateProperties();
  421.          var _loc2_:CollectionEvent = new CollectionEvent(CollectionEvent.COLLECTION_CHANGE);
  422.          _loc2_.kind = CollectionEventKind.RESET;
  423.          collectionChangeHandler(_loc2_);
  424.          dispatchEvent(_loc2_);
  425.       }
  426.       
  427.       public function get showRoot() : Boolean
  428.       {
  429.          return _showRoot;
  430.       }
  431.       
  432.       public function validateDisplayList() : void
  433.       {
  434.       }
  435.       
  436.       protected function parseLabelToString(param1:String) : String
  437.       {
  438.          var _loc7_:String = null;
  439.          var _loc2_:RegExp = new RegExp(MNEMONIC_INDEX_CHARACTER,"g");
  440.          var _loc3_:RegExp = new RegExp(MNEMONIC_INDEX_CHARACTER + MNEMONIC_INDEX_CHARACTER,"g");
  441.          var _loc4_:Array = param1.split(_loc3_);
  442.          var _loc5_:int = int(_loc4_.length);
  443.          var _loc6_:int = 0;
  444.          while(_loc6_ < _loc5_)
  445.          {
  446.             _loc7_ = String(_loc4_[_loc6_]);
  447.             _loc4_[_loc6_] = _loc7_.replace(_loc2_,"");
  448.             _loc6_++;
  449.          }
  450.          return _loc4_.join(MNEMONIC_INDEX_CHARACTER);
  451.       }
  452.       
  453.       public function set keyEquivalentModifiersFunction(param1:Function) : void
  454.       {
  455.          if(_keyEquivalentModifiersFunction != param1)
  456.          {
  457.             _keyEquivalentModifiersFunction = param1;
  458.             keyEquivalentModifiersFunctionChanged = true;
  459.             invalidateProperties();
  460.             dispatchEvent(new Event("keyEquivalentModifiersFunctionChanged"));
  461.          }
  462.       }
  463.       
  464.       public function get hasRoot() : Boolean
  465.       {
  466.          return _hasRoot;
  467.       }
  468.       
  469.       public function set keyEquivalentField(param1:String) : void
  470.       {
  471.          if(_keyEquivalentField != param1)
  472.          {
  473.             _keyEquivalentField = param1;
  474.             keyEquivalentFieldChanged = true;
  475.             invalidateProperties();
  476.             dispatchEvent(new Event("keyEquivalentFieldChanged"));
  477.          }
  478.       }
  479.       
  480.       protected function itemToLabel(param1:Object) : String
  481.       {
  482.          var data:Object = param1;
  483.          if(data == null)
  484.          {
  485.             return " ";
  486.          }
  487.          if(labelFunction != null)
  488.          {
  489.             return labelFunction(data);
  490.          }
  491.          if(data is XML)
  492.          {
  493.             try
  494.             {
  495.                if(data[labelField].length() != 0)
  496.                {
  497.                   data = data[labelField];
  498.                }
  499.             }
  500.             catch(e:Error)
  501.             {
  502.             }
  503.          }
  504.          else if(data is Object)
  505.          {
  506.             try
  507.             {
  508.                if(data[labelField] != null)
  509.                {
  510.                   data = data[labelField];
  511.                }
  512.             }
  513.             catch(e:Error)
  514.             {
  515.             }
  516.          }
  517.          else if(data is String)
  518.          {
  519.             return String(data);
  520.          }
  521.          try
  522.          {
  523.             return data.toString();
  524.          }
  525.          catch(e:Error)
  526.          {
  527.          }
  528.          return " ";
  529.       }
  530.       
  531.       public function set initialized(param1:Boolean) : void
  532.       {
  533.          _initialized = param1;
  534.       }
  535.       
  536.       [Bindable("mnemonicIndexChanged")]
  537.       public function get mnemonicIndexField() : String
  538.       {
  539.          return _mnemonicIndexField;
  540.       }
  541.       
  542.       public function get processedDescriptors() : Boolean
  543.       {
  544.          return _processedDescriptors;
  545.       }
  546.       
  547.       public function get dataDescriptor() : IMenuDataDescriptor
  548.       {
  549.          return IMenuDataDescriptor(_dataDescriptor);
  550.       }
  551.       
  552.       [Bindable("collectionChange")]
  553.       public function get dataProvider() : Object
  554.       {
  555.          if(mx_internal::_rootModel)
  556.          {
  557.             return mx_internal::_rootModel;
  558.          }
  559.          return null;
  560.       }
  561.       
  562.       public function display(param1:Stage, param2:int, param3:int) : void
  563.       {
  564.          nativeMenu.display(param1,param2,param3);
  565.       }
  566.       
  567.       protected function commitProperties() : void
  568.       {
  569.          var _loc1_:ICollectionView = null;
  570.          var _loc2_:* = undefined;
  571.          if(showRootChanged)
  572.          {
  573.             if(!_hasRoot)
  574.             {
  575.                showRootChanged = false;
  576.             }
  577.          }
  578.          if(dataProviderChanged || showRootChanged || labelFieldChanged || dataDescriptorChanged)
  579.          {
  580.             dataProviderChanged = false;
  581.             showRootChanged = false;
  582.             labelFieldChanged = false;
  583.             dataDescriptorChanged = false;
  584.             if(mx_internal::_rootModel && !_showRoot && _hasRoot)
  585.             {
  586.                _loc2_ = mx_internal::_rootModel.createCursor().current;
  587.                if(_loc2_ != null && _dataDescriptor.isBranch(_loc2_,mx_internal::_rootModel) && _dataDescriptor.hasChildren(_loc2_,mx_internal::_rootModel))
  588.                {
  589.                   _loc1_ = _dataDescriptor.getChildren(_loc2_,mx_internal::_rootModel);
  590.                }
  591.             }
  592.             clearMenu(_nativeMenu);
  593.             if(mx_internal::_rootModel)
  594.             {
  595.                if(!_loc1_)
  596.                {
  597.                   _loc1_ = mx_internal::_rootModel;
  598.                }
  599.                _loc1_.addEventListener(CollectionEvent.COLLECTION_CHANGE,collectionChangeHandler,false,EventPriority.DEFAULT_HANDLER,true);
  600.                populateMenu(_nativeMenu,_loc1_);
  601.             }
  602.             dispatchEvent(new Event("nativeMenuChange"));
  603.          }
  604.       }
  605.       
  606.       public function unsetContextMenu(param1:InteractiveObject) : void
  607.       {
  608.          param1.contextMenu = null;
  609.       }
  610.       
  611.       public function invalidateProperties() : void
  612.       {
  613.          var _loc1_:Timer = null;
  614.          if(!invalidatePropertiesFlag && nestLevel > 0)
  615.          {
  616.             invalidatePropertiesFlag = true;
  617.             if(UIComponentGlobals.mx_internal::layoutManager)
  618.             {
  619.                UIComponentGlobals.mx_internal::layoutManager.invalidateProperties(this);
  620.             }
  621.             else
  622.             {
  623.                _loc1_ = new Timer(100,1);
  624.                _loc1_.addEventListener(TimerEvent.TIMER,validatePropertiesTimerHandler);
  625.                _loc1_.start();
  626.             }
  627.          }
  628.       }
  629.       
  630.       public function set labelField(param1:String) : void
  631.       {
  632.          if(_labelField != param1)
  633.          {
  634.             _labelField = param1;
  635.             labelFieldChanged = true;
  636.             invalidateProperties();
  637.             dispatchEvent(new Event("labelFieldChanged"));
  638.          }
  639.       }
  640.       
  641.       public function get initialized() : Boolean
  642.       {
  643.          return _initialized;
  644.       }
  645.       
  646.       public function validatePropertiesTimerHandler(param1:TimerEvent) : void
  647.       {
  648.          validateProperties();
  649.       }
  650.       
  651.       public function set labelFunction(param1:Function) : void
  652.       {
  653.          if(_labelFunction != param1)
  654.          {
  655.             _labelFunction = param1;
  656.             labelFieldChanged = true;
  657.             invalidateProperties();
  658.             dispatchEvent(new Event("labelFunctionChanged"));
  659.          }
  660.       }
  661.       
  662.       protected function itemToKeyEquivalentModifiers(param1:Object) : Array
  663.       {
  664.          if(param1 == null)
  665.          {
  666.             return [];
  667.          }
  668.          if(keyEquivalentModifiersFunction != null)
  669.          {
  670.             return keyEquivalentModifiersFunction(param1);
  671.          }
  672.          return [];
  673.       }
  674.       
  675.       protected function itemToKeyEquivalent(param1:Object) : String
  676.       {
  677.          var data:Object = param1;
  678.          if(data == null)
  679.          {
  680.             return "";
  681.          }
  682.          if(keyEquivalentFunction != null)
  683.          {
  684.             return keyEquivalentFunction(data);
  685.          }
  686.          if(data is XML)
  687.          {
  688.             try
  689.             {
  690.                if(data[keyEquivalentField].length() != 0)
  691.                {
  692.                   data = data[keyEquivalentField];
  693.                   return data.toString();
  694.                }
  695.             }
  696.             catch(e:Error)
  697.             {
  698.             }
  699.          }
  700.          else if(data is Object)
  701.          {
  702.             try
  703.             {
  704.                if(data[keyEquivalentField] != null)
  705.                {
  706.                   data = data[keyEquivalentField];
  707.                   return data.toString();
  708.                }
  709.             }
  710.             catch(e:Error)
  711.             {
  712.             }
  713.          }
  714.          return "";
  715.       }
  716.       
  717.       public function validateNow() : void
  718.       {
  719.          if(invalidatePropertiesFlag)
  720.          {
  721.             validateProperties();
  722.          }
  723.       }
  724.       
  725.       private function insertMenuItem(param1:NativeMenu, param2:int, param3:Object) : void
  726.       {
  727.          var _loc7_:String = null;
  728.          var _loc8_:int = 0;
  729.          if(dataProviderChanged)
  730.          {
  731.             commitProperties();
  732.             return;
  733.          }
  734.          var _loc4_:String = dataDescriptor.getType(param3).toLowerCase();
  735.          var _loc5_:* = _loc4_ == "separator";
  736.          var _loc6_:NativeMenuItem = new NativeMenuItem("",_loc5_);
  737.          if(!_loc5_)
  738.          {
  739.             _loc6_.enabled = dataDescriptor.isEnabled(param3);
  740.             _loc6_.checked = _loc4_ == "check" && dataDescriptor.isToggled(param3);
  741.             _loc6_.data = dataDescriptor.getData(param3,mx_internal::_rootModel);
  742.             _loc6_.keyEquivalent = itemToKeyEquivalent(param3);
  743.             _loc6_.keyEquivalentModifiers = itemToKeyEquivalentModifiers(param3);
  744.             _loc7_ = itemToLabel(param3);
  745.             _loc8_ = itemToMnemonicIndex(param3);
  746.             if(_loc8_ >= 0)
  747.             {
  748.                _loc6_.label = parseLabelToString(_loc7_);
  749.                _loc6_.mnemonicIndex = _loc8_;
  750.             }
  751.             else
  752.             {
  753.                _loc6_.label = parseLabelToString(_loc7_);
  754.                _loc6_.mnemonicIndex = parseLabelToMnemonicIndex(_loc7_);
  755.             }
  756.             _loc6_.addEventListener(Event.SELECT,itemSelectHandler,false,0,true);
  757.             if(dataDescriptor.isBranch(param3,mx_internal::_rootModel) && dataDescriptor.hasChildren(param3,mx_internal::_rootModel))
  758.             {
  759.                _loc6_.submenu = createMenu();
  760.                populateMenu(_loc6_.submenu,dataDescriptor.getChildren(param3,mx_internal::_rootModel));
  761.             }
  762.          }
  763.          param1.addItem(_loc6_);
  764.       }
  765.       
  766.       public function setContextMenu(param1:InteractiveObject) : void
  767.       {
  768.          var _loc2_:ISystemManager = null;
  769.          param1.contextMenu = nativeMenu;
  770.          if(param1 is Application)
  771.          {
  772.             _loc2_ = Application(param1).systemManager;
  773.             if(_loc2_ is InteractiveObject)
  774.             {
  775.                InteractiveObject(_loc2_).contextMenu = nativeMenu;
  776.             }
  777.          }
  778.       }
  779.       
  780.       protected function itemToMnemonicIndex(param1:Object) : int
  781.       {
  782.          var mnemonicIndex:int = 0;
  783.          var data:Object = param1;
  784.          if(data == null)
  785.          {
  786.             return -1;
  787.          }
  788.          if(mnemonicIndexFunction != null)
  789.          {
  790.             return mnemonicIndexFunction(data);
  791.          }
  792.          if(data is XML)
  793.          {
  794.             try
  795.             {
  796.                if(data[mnemonicIndexField].length() != 0)
  797.                {
  798.                   mnemonicIndex = int(data[mnemonicIndexField]);
  799.                   return mnemonicIndex;
  800.                }
  801.             }
  802.             catch(e:Error)
  803.             {
  804.             }
  805.          }
  806.          else if(data is Object)
  807.          {
  808.             try
  809.             {
  810.                if(data[mnemonicIndexField] != null)
  811.                {
  812.                   mnemonicIndex = int(data[mnemonicIndexField]);
  813.                   return mnemonicIndex;
  814.                }
  815.             }
  816.             catch(e:Error)
  817.             {
  818.             }
  819.          }
  820.          return -1;
  821.       }
  822.       
  823.       public function validateProperties() : void
  824.       {
  825.          if(invalidatePropertiesFlag)
  826.          {
  827.             commitProperties();
  828.             invalidatePropertiesFlag = false;
  829.          }
  830.       }
  831.       
  832.       [Bindable("labelFunctionChanged")]
  833.       public function get labelFunction() : Function
  834.       {
  835.          return _labelFunction;
  836.       }
  837.       
  838.       public function set showRoot(param1:Boolean) : void
  839.       {
  840.          if(_showRoot != param1)
  841.          {
  842.             showRootChanged = true;
  843.             _showRoot = param1;
  844.             invalidateProperties();
  845.          }
  846.       }
  847.    }
  848. }
  849.  
  850.